<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<?php
if(!isset($_SESSION)){
	session_start();
}

if(!isset($_SESSION["adminName"]) || (empty($_SESSION["adminName"]))){
	header ("Location: ../index.php");
}
?>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Add Page</title>
    <link href="../../Styles/adminstype.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../js/admin_script.js"></script>
</head>
<body>
<?php
$comboBox = "";
if(empty($_REQUEST["btnThem"]))//có yeu cau them
{
	// tạo combo loai tai khoảng
	$width = 160;;
	$name ="LoaiTK";
	$active_sltTenTH = 0;
	$tatca = "Tất Cả";
	$comboBox = '<select style="width:'.$width.'px" name="'.$name.'" id="'.$name.'" >'."\n";

	$sql = "select * from loaitaikhoan";
	require_once "../database/DataProvider.php";
	$result =  DataProvider::ExecuteQuery($sql);

	if(!empty($result)){
		while($row = mysql_fetch_array($result))
		{
			$comboBox .= '<option value="'.$row["MaLoaiTaiKhoan"].'"';
			if($active_sltTenTH == $row["MaLoaiTaiKhoan"]) $comboBox .= ' selected="selected" ';
			$comboBox .= '>'.$row["TenLoaiTaiKhoan"]."</option>\n";
		}
	}
	$comboBox .= "</select>\n";
}
?>
<table>
	<tr class="boxContentTitle">
		<td>Thêm người dùng</td>
	</tr>
	<tr>
		<td>
			 <form action="resource/form_add_account.php" method="post" name="form_add_account">
				<table class="tableBoxView">
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Tên người dùng</td>
						<td><input type="text" maxlength="64" name="txtTen" id="txtTen" /></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Mật Khẩu</td>
						<td><input type="password" maxlength="64" name="txtPass" id="txtPass" /></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Tên hiển thị</td>
						<td><input type="text" maxlength="64" name="txtTenHienThi" id="txtTenHienThi" /></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Địa chỉ</td>
						<td><input type="text" maxlength="600" name="txtDiaChi" id="txtDiaChi" /></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Điện thoại</td>
						<td><input type="text" maxlength="20" name="txtDienThoai" id="txtDienThoai"/></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Email</td>
						<td><input type="text" maxlength="200" name="txtEmail" id="txtEmail" /></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Loại tài khoảng</td>
						<td><?php echo($comboBox);?></td>
					</tr>
					<tr>
						<td><td>
						<td></td>
						<td><input type="submit" name="btnThem" value="Save" onclick="return kiemTraTxt3('txtTen', 'txtPass', 'txtTenHienThi')"/></td>
					</tr>
				</table>
			</form>
		</td>
	</tr>
	<tr>
		<td>
			<?php
			if(!empty($_REQUEST["btnThem"]))//có yeu cau them
			{
				$tenTK = $_REQUEST["txtTen"];
				$pass = $_REQUEST["txtPass"];
				$tenHT = $_REQUEST["txtTenHienThi"];
				$diaChi = $_REQUEST["txtDiaChi"];
				$dienThoai = $_REQUEST["txtDienThoai"];
				$email = $_REQUEST["txtEmail"];
				$loaiTK = $_REQUEST["LoaiTK"];
				if($tenTK != "") //kiểm tra 
				{
					$sql = "insert into taikhoan(TenDangNhap, MatKhau, TenHienThi, DiaChi, DienThoai, Email, BiXoa, MaLoaiTaiKhoan)
					values('$tenTK', '$pass', '$tenHT', '$diaChi', '$dienThoai', '$email', 0, $loaiTK)";
					echo($sql);
					require_once "../../database/DataProvider.php";
					$result =  DataProvider::ExecuteQuery($sql);
				}
				header ("Location: ../admin_manager_account.php");
			}
			?>
		</td>
	</tr>
</table>
</body>
</html>
